const { override, fixBabelImports, addWebpackExternals, addWebpackPlugin } = require('customize-cra');
const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer');
const CompressionWebpackPlugin = require('compression-webpack-plugin');
const addCustomize = () => config => {
  if (process.env.NODE_ENV === 'production') {
    // 关闭sourceMap
    config.devtool = false;
    // 配置打包后的文件位置
    // config.output.path = __dirname + '/dist/';
    // config.output.publicPath = '/admin-meeting'; //package.json中homepage配置
    // 添加js打包gzip配置
    config.plugins.push(
      new CompressionWebpackPlugin({
        test: /\.js$|\.css$/,
        threshold: 1024,
      }),
    )
  }
  return config;
}
module.exports = {
  webpack: override(
		// antd按需加载
    // fixBabelImports('antd', {
    //   libraryName: 'antd',
    //   libraryDirectory: 'es',
    //   style: true,
    // }),
    addCustomize(),
    addWebpackPlugin(
      new BundleAnalyzerPlugin({
        analyzerMode: 'static', //输出静态报告文件report.html，而不是启动一个web服务
      })
    ),
    //别名
    // addWebpackAlias({
    //   ["ag-grid-react$"]: path.resolve(__dirname, "src/shared/agGridWrapper.js")
    // }),
  )
}

